package com.qingcheng.controller.goods;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.goods.Brand;
import com.qingcheng.service.goods.BrandService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by chendx on 2021/5/21.
 */
@RestController
@RequestMapping("/brand")
public class BrandController {


    @Reference
    private BrandService brandService;


    @RequestMapping("/findAll")
    public List<Brand> findAll(){
        return brandService.findAll();
    }
    @GetMapping("/findById")
    public Brand findById(Integer id){
        return brandService.findById(id);
    }

    @GetMapping("/findPage")
    public PageResult<Brand> findPage(Integer currentPage,Integer pageSize){
        return brandService.findPage(currentPage,pageSize);
    }

    @PostMapping("/findByCondition")
    public List<Brand> findByCondition(@RequestBody Map<String,Object> map){
        return brandService.findByCondition(map);
    }

    @PostMapping("/findByConditionPage")
    public PageResult<Brand> findByConditionPage(@RequestBody Map<String,Object> map ,Integer currentPage,Integer pageSize){
        return brandService.findByConditionPage(map,currentPage,pageSize);
    }

    @PostMapping("/insert")
    public Result insert(@RequestBody Brand brand){
        try {
            brandService.insert(brand);
            return new Result();
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(1,"执行失败");
        }
    }
    @PostMapping("/update")
    public Result update(@RequestBody Brand brand){
        try {
            brandService.update(brand);
            return new Result();
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(1,"执行失败");
        }
    }
    @GetMapping("/deleteById")
    public Result deleteById(Integer id){
        try {
            brandService.deleteById(id);
            return new Result();
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(1,"执行失败");
        }
    }
}
